﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
 
using CenterDateAchieve.Helper;
using CenterDateAchieve.Forms;
using IBLL.Controller;
using CenterDateAchieve.Controller;
using BLL.Controller;
using AppToolKit.Core.Context.Spring;
using BLL.Business;



namespace CenterDateAchieve
{
    public partial class TaskListForm : FormBase
    {
        private const string CheckRow = "choose";
        [AutoWiring]
        public ControllerFactory ControllerFactoryHolder { get; set; }

        [AutoWiring]
        public FormBusiness FormBusinessHolder { get; set; }

        [AutoWiring]
        public TaskFaced TaskFacedHolder { get; set; }

       
        public TaskListForm()
        {
            InitializeComponent();
        }

     


        private void btNew_Click(object sender, EventArgs e)
        {
            IFormController controller = ControllerFactoryHolder.GetController<HotelController, HotelDefineForm>();

            controller.Show();

        }

        private void TaskListForm_Load(object sender, EventArgs e)
        {
            try
            {
                TreeViewHelper.BulidTreeView(this.treeHotel, "酒店", TaskFacedHolder.GetHotelAll(), null);
                treeHotel.ExpandAll();

                BulidTaskList(string.Empty);

              
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        void BulidTaskList(string hotelid)
        {
            TreeViewHelper.BulidTreeView(this.treeTaskList, "任务", TaskFacedHolder.GetTaskListAll(hotelid), null);
            treeTaskList.ExpandAll();
        }
       

        private void btExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

      
        TreeNode CurrentNode = null;
       


        private void treeView1_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            IFormController controller = ControllerFactoryHolder.GetController<HotelController, HotelDefineForm>(e.Node.Name);

            controller.Show();
        }
       
        private void treeHotel_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (e.Node.Level == 1)
            {
                if(CurrentNode!=null)
                CurrentNode.ForeColor = Color.Black;
                CurrentNode = e.Node;
                e.Node.ForeColor = Color.Red;
                BulidTaskList(e.Node.Name);
            }
            else
            {
                if (CurrentNode != null)
                    CurrentNode.ForeColor = Color.Black;
                CurrentNode = null;
            }
        }

       
        private void btSave_Click(object sender, EventArgs e)
        {

            if (CurrentNode == null)
                return;

            List<string> tasklists = TreeViewHelper.GetCheckedNodes(treeTaskList.Nodes[0]);


            TaskFacedHolder.SaveAlloment(CurrentNode.Name, tasklists);
        }

        private void btTask_Click(object sender, EventArgs e)
        {
           TaskDistributeForm form=  ContextAwareHolder.Create<TaskDistributeForm>();
           form.ShowDialog();
        }

        private void treeTaskList_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
        {
           
            IFormController controller = ControllerFactoryHolder.GetController<TaskListController, ListDefineForm>(e.Node.Name);

            controller.Show();
        }

        
    }
}
